﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public struct SphereBounds
    {
        public Vector3 Center { get; set; }
        public float Radius { get; set; }
        public SphereBounds(Vector3 center, float radius)
        {
            this.Center = center;
            this.Radius = radius;
        }
        /// <summary>
        /// 相交
        /// </summary>
        public bool Intersects(SphereBounds bounds)
        {
            float sqrMagnitude = (this.Center - bounds.Center).sqrMagnitude;
            float num = this.Radius + bounds.Radius;
            return sqrMagnitude <= num * num;
        }

        public bool Intersects(Bounds bounds)
        {
            if (bounds.Contains(this.Center))
            {
                return true;
            }
            Vector3 min = bounds.min;
            Vector3 max = bounds.max;
            float num = 0f;
            if (this.Center.x < min.x)
            {
                float num2 = this.Center.x - min.x;
                num += num2 * num2;
            }
            else if (this.Center.x > max.x)
            {
                float num2 = this.Center.x - max.x;
                num += num2 * num2;
            }
            if (this.Center.y < min.y)
            {
                float num2 = this.Center.y - min.y;
                num += num2 * num2;
            }
            else if (this.Center.y > max.y)
            {
                float num2 = this.Center.y - max.y;
                num += num2 * num2;
            }
            if (this.Center.z < min.z)
            {
                float num2 = this.Center.z - min.z;
                num += num2 * num2;
            }
            else if (this.Center.z > max.z)
            {
                float num2 = this.Center.z - max.z;
                num += num2 * num2;
            }
            return num <= this.Radius * this.Radius;
        }







    }
}

